package com.itcast.framdemo.utils;/*
package com.itcast.framdemo.utils;


import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

*/


import java.util.Calendar;
import java.util.Date;
import java.util.Map;

/**
 * @author WangCong
 * 2024/12/10 20:28
 */
/*

public class JWTUtils {
    private static String key="1suo";
    //通过jwt创建token令牌
    public static String createToken(Map<String,Object> map){
        Date date=new Date();//发布日期
        Calendar instance = Calendar.getInstance();//获取当前时间
        instance.set(Calendar.SECOND,7200);//在当前时间的基础上添加7200秒
        Date time = instance.getTime();

        String token = JWT.create()
                .withIssuedAt(date) //设置发布日期
                .withExpiresAt(time) //设置过期时间
                .withClaim("userinfo", map) //设置个人信息
                .sign(Algorithm.HMAC256(key));//签名

        return token;
    }

    //校验token
    public static boolean verify(String token){
        Verification require = JWT.require(Algorithm.HMAC256(key));
        try {
            require.build().verify(token);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    //根据token获取自定义的信息
    public static Map<String,Object> getInfo(String token,String mykey){
        JWTVerifier build = JWT.require(Algorithm.HMAC256(key)).build();
        Claim claim = build.verify(token).getClaim(mykey);
        return claim.asMap();
    }
}
*/
